var app = new Vue({
    el: '#app',
    data: {
        list: [
            {
                id: 1,
                name: '苹果',
                price: 1000,
                count: 1,
                ischeck:true
            },
            {
                id: 2,
                name: '小米',
                price: 1928,
                count: 1,
                ischeck:true
            },
            {
                id: 3,
                name: '华为',
                price: 6055,
                count: 1,
                ischeck:true
            },
            {
                id: 1,
                name: 'vivo ',
                price: 2288,
                count: 1,
                ischeck:true
            }
        ],
        inputCheck:true,
    },
    computed: {
        totalPrice: function () {
            var total = 0;
            for (var i = 0; i < this.list.length; i++) {
                var item = this.list[i];
                total += item.price * item.count;
            }

            return total.toString().replace(/\B(?=(\d{3})+$)/g,',');
        }
    },
    methods: {
        handleReduce: function (index) {
            if (this.list[index].count === 1) return;
            this.list[index].count--;
        },
        handleAdd: function (index) {
            this.list[index].count++;
        },
        handleRemove: function (index) {
            this.list.splice(index, 1);
        },
        handChange:function()
        {
            this.list.forEach(element => {
                element.ischeck=this.inputCheck
            });
        },
        inputChange:function()
        {
            var unselected = true;
            this.list.forEach(element => {
                if(element.ischeck===false)
                {
                    unselected=false;
                }
            });   
            if(unselected ===false)
            {
                this.inputCheck = false;
            }else{
                this.inputCheck = true;
            }
        }
    }

});
